#include "menubuilder.h"

#include <QDebug>
#include <QAction>
#include <QMenu>
#include <QFile>

#include "mainwindow.h"
#include "sconst.h"

MenuBuilder::MenuBuilder(QWidget *parent) :
    QMenuBar(parent)
{
    initActionMenu();
    initViewMenu();
    initEditMenu();
}

void MenuBuilder::initActionMenu()
{
  QMenu *pActionMenu = addMenu(SC_ACTION);

/*********** MENU ITEM: LOGIN *******************/
  QPixmap login_pix(SC_IMG_APP_EXIT);
  QIcon   icon_login(login_pix);
  QAction *pActLogin = new QAction(icon_login, SC_LOGIN, this->parent());

  pActLogin->setIconVisibleInMenu(true);
  connect(pActLogin, SIGNAL(triggered()), this->parentWidget(), SLOT(signalLoginDataBase()));

/*********** MENU ITEM: EXIT *******************/
  QPixmap exit_pix(SC_IMG_APP_EXIT);
  QIcon   icon_exit(exit_pix);
  QAction *pActExit = new QAction(icon_exit, SC_EXIT, this->parent());

  pActExit->setIconVisibleInMenu(true);
  connect(pActExit, SIGNAL(triggered()), this->parentWidget(), SLOT(signalExit()));



  pActionMenu->addAction(pActLogin);
  pActionMenu->addSeparator();
  pActionMenu->addAction(pActExit);
}

void MenuBuilder::initEditMenu()
{
  QMenu *pEditMenu = addMenu(SC_EDIT);

/*********** MENU ITEM: EDIT *******************/
  QPixmap errorcode_pix(SC_IMG_ERROR_CODE);
  QIcon   icon_errorcode(errorcode_pix);
  QAction *pActErrorCode = new QAction(icon_errorcode, SC_ERROR_CODE, this->parent());

  pActErrorCode->setIconVisibleInMenu(true);
  connect(pActErrorCode, SIGNAL(triggered()), this->parentWidget(), SLOT(signalOpenErrorCodeEditTable()));

  pEditMenu->addAction(pActErrorCode);
}

void MenuBuilder::initViewMenu()
{
  QMenu *pViewMenu = addMenu(SC_VIEW);

/*********** MENU ITEM: VIEW *******************/
  QPixmap errorcode_pix(SC_IMG_ERROR_CODE);
  QIcon   icon_errorcode(errorcode_pix);
  QAction *pActErrorCode = new QAction(icon_errorcode, SC_ERROR_CODE, this->parent());

  pActErrorCode->setIconVisibleInMenu(true);
  connect(pActErrorCode, SIGNAL(triggered()), this->parentWidget(), SLOT(signalOpenErrorCodeViewTable()));

  pViewMenu->addAction(pActErrorCode);
}
